//
//  YYForRecordVC.m
//  drivingSchool
//
//  Created by 子yu 刘 on 2018/8/13.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "YYForRecordVC.h"
#import "YYRecodeCell.h"

@interface YYForRecordVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong)NSMutableArray * dataArray;

@end

@implementation YYForRecordVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self getData];
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        self.pageNO = 1;
        [self.dataArray removeAllObjects];
        [self getData];
        
    }];
    self.tableView.mj_footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        self.pageNO++;
        [self getData];
    }];
}

- (void)getData{
    [RequestOperationManager personalIntegralExchange_page:self.pageString success:^(id result) {
        [self.tableView.mj_header endRefreshing];
        if (DEF_REQ_SUCCESS) {
            NSArray * array = result[@"data"][@"data"];
            [self.dataArray addObjectsFromArray:array];
            if (self.dataArray.count == 0) {
                self.baseLabel.text = @"暂无兑换记录";
                self.baseImageView.hidden = NO;
            }else{
                [self.tableView reloadData];
            }
            if (array.count == 0) {
                [self.tableView.mj_footer endRefreshingWithNoMoreData];
            }else{
                [self.tableView.mj_footer endRefreshing];
            }
            [self.tableView reloadData];
        }else{
               [self.tableView.mj_footer endRefreshing];
        }
        
    } failture:^(NSError *error) {
        [self.tableView.mj_header endRefreshing];
        [self.tableView.mj_footer endRefreshing];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    YYRecodeCell * cell = [tableView dequeueReusableCellWithIdentifier:@"YYRecodeCell"];
    NSDictionary * itme = _dataArray[indexPath.row];
    cell.lbTitle.text = itme[@"product"];
    if ([itme[@"money"] floatValue]>0) {
          cell.lbRecode.text = [NSString stringWithFormat:@"-%@积分+%@元",itme[@"integral"],itme[@"money"]];
    }else{
          cell.lbRecode.text = [NSString stringWithFormat:@"-%@积分",itme[@"integral"]];
    }
  
    cell.lbData.text = [DateUtil getDateWithTimeInterval:itme[@"time"] type:@"yyyy/MM/dd"];
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
}

-(NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}

@end
